package com.bookmarket.controller;

import com.bookmarket.entity.Accident;
import com.bookmarket.service.IAccidentService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/accident")
@SessionAttributes(names="list")
public class WzAccidentController {

    @Resource
    private IAccidentService accidentService;

    @RequestMapping("/findAll")
    public ModelAndView findAll() {
        ModelAndView mv=new ModelAndView();
        List<Accident> list=accidentService.findAll();
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping("/getPage")
    public Map queryUsersByPage(int pageNum, int pageSize, Accident accident) {
        Map map = new HashMap();
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("accident", accident);
        Page page = accidentService.queryLikeUsers(map);

        map.put("page", page);
        map.put("totalPage", page.getPages());
        return map;
    }

    public IAccidentService getAccidentService() {
        return accidentService;
    }

    public void setAccidentService(IAccidentService accidentService) {
        this.accidentService = accidentService;
    }
}
